var Yiyonghaocai = new Vue({
    el : "#Yiyonghaocailist",
    data :{
        xiangmuId : $("#xiangmuId").val(),
        xiangmuleixing: "",
        xiangmu : {},
        yiyonghaocai :{},
        yiyonghaocailist : [],
        show : false,					// 显示列表是否有数据

        pageIndex : 1,
        pageSize :9999,
        pageCount : 0,
        recordCount : 0,
        inputPageIndexValue : "",

    },

    created : function() {
        var _this = this;
        xiangmuId=_this.xiangmuId;
        _this.bindYiyonghaocaiList();
        _this.bindXiangmu();

    },
    methods : {
        toback : function() {
            window.history.go(-1);
        },
        bindXiangmu:function (){
            var _this = this;
            layer.open({type:3});
            $.post('/xiangmu/find_one', {
                xianmguid : _this.xiangmuId,
                rdm : Math.random()
            },function(ppData) {
                layer.closeAll("loading");
                if(ppData != null){
                    if(ppData.result == "1"){
                        var data = ppData.resultContent;
                        _this.xiangmu = data;
                        _this.xiangmuleixing = data.xiangmuleixing;
                    }else{
                        layer.alert(ppData.message);
                    }
                }
            },"json");
        },
        toDelete:function (){
            var _this = this;

            layer.confirm("确定删除该项目的材料吗？",{
                btn : ['是','否']
            },function(){
                layer.open({type:3});

                $.post("/hc3/delete", {
                    xiangmuid : _this.xiangmuId,
                    random : Math.random()
                }, function(ppData) {
                    if (ppData != null) {
                        layer.closeAll("loading");

                        if(ppData.result != "1"){
                            layer.alert(ppData.message);
                        }else{
                            layer.open({
                                time:1000,
                                btn:[],
                                content:"删除成功!",
                            });

                            _this.bindYiyonghaocaiList();
                            _this.bindXiangmu();
                        }
                    }
                },"json");
            })
        },

        bindYiyonghaocaiList:function (){
            var _this = this;
            layer.open({type:3});
            $.post("/hc3/findhc3list",{
                xiangmuid : _this.xiangmuId,
                pageindex : _this.pageIndex,
                pagesize : _this.pageSize,
                rdm : Math.random()
            },function(ppData){
                layer.closeAll("loading");
                if (ppData != null){
                    if(ppData.result == "1"){
                        var data=ppData.resultContent;
                        var mmHtml = "<table class=\"table table-hover table-bordered\" style=\"overflow:hidden; margin-bottom:10px;table-layout:fixed;\" v-if=\"show\" cellspacing=\"0\" cellpadding=\"0\">\n" +
                            "   <thead >\n" +
                            "       <th style=\"text-align:center;vertical-align:middle;width:80px;\" >引进类型</th>\n" +
                            "       <th style=\"text-align:center;vertical-align:middle;width:60px;\" >序号</th>\n" +
                            "       <th style=\"text-align:center;vertical-align:middle;\" >带量备注</th>\n" +
                            "       <th style=\"text-align:center;vertical-align:middle;\" >产品类别</th>\n" +
                            "       <th style=\"text-align:center;vertical-align:middle;\" >中标编码</th>\n" +
                            "       <th style=\"text-align:center;vertical-align:middle;\" >注册证名称</th>\n" +
                            "       <th style=\"text-align:center;vertical-align:middle;\" >规格</th>\n" +
                            "       <th style=\"text-align:center;vertical-align:middle;width:80px;\" >型号</th>\n" +
                            "       <th style=\"text-align:center;vertical-align:middle;\" >注册证号</th>\n" +
                            "       <th style=\"text-align:center;vertical-align:middle;\" >生产商</th>\n" +
                            "       <th style=\"text-align:center;vertical-align:middle;width:60px;\" >单位</th>\n" +
                            "       <th style=\"text-align:center;vertical-align:middle;width:80px;\" >价格</th>\n" +
                            "    </thead>";
                        if(data.Hc3List.length > 0){
                            _this.show = true;
                            _this.yiyonghaocailist=data.Hc3List;

                            var PageInfo = data.PageInfo;
                            _this.pageIndex = PageInfo.pageIndex;
                            _this.recordCount = PageInfo.recordCount;
                            _this.pageCount = PageInfo.pageCount;

                            for (var i = 0; i < data.Hc3List.length; i++) {
                                var s=0;
                                var mmYiyonghaocai = data.Hc3List[i];
                                var mmXinghaoList = mmYiyonghaocai.xinghaolist;
                                var mmPinpaiHebingshu = mmYiyonghaocai.pinpaihebingshu;

                                for (var j = 0; j < mmXinghaoList.length; j++) {


                                    var mmXinghaolist = mmXinghaoList[j];
                                    var mmYinjinleixing = mmXinghaolist.beizhu1;
                                    var mmXuhao = mmXinghaolist.xuhao;
                                    var mmOrdernumber = mmXinghaolist.ordernum;
                                    var mmDailiangbeizhu = mmXinghaolist.beizhu2;
                                    var mmChanpinleibie = mmXinghaolist.beizhu3;
                                    var mmZhongbiaobianma = mmXinghaolist.zhongbiaobianma;
                                    var mmZhucezhengmingcheng = mmXinghaolist.beizhu3;
                                    var mmGuige = mmXinghaolist.guige;
                                    var mmXinghao = mmXinghaolist.xinghao;
                                    var mmZhucezhenghao = mmXinghaolist.zhucezheng;
                                    var mmShengchanshang = mmXinghaolist.shengchanchangjia;
                                    var mmdanwei = mmXinghaolist.danwei;
                                    var mmjiage = mmXinghaolist.danjia;

                                    var mmHuanhangfu = "";
                                    var mmerjihe="";
                                    var mmyijihe="";
                                    mmHtml +="<td style='text-align:center;vertical-align:middle;width: 49px;height: 100%'>" + mmYinjinleixing + "</td>";
                                    mmHtml +="<td style='text-align:center;vertical-align:middle;width: 49px;height: 100%'>" + mmXuhao + "</td>";
                                    mmHtml +="<td style='text-align:center;vertical-align:middle;width: 49px;height: 100%'>" + mmDailiangbeizhu + "</td>";
                                    mmHtml +="<td style='text-align:center;vertical-align:middle;width: 49px;height: 100%'>" + mmChanpinleibie + "</td>";
                                    mmHtml += "<td style='text-align:center;vertical-align:middle;width:100px;white-space:nowrap;text-overflow: ellipsis; overflow: hidden;'><a title='" + mmZhongbiaobianma + "'>" + mmZhongbiaobianma + "</a></td>";
                                    mmHtml += "<td style='text-align:center;vertical-align:middle;'>" + mmZhucezhengmingcheng + "</td>";
                                    mmHtml += "<td style='text-align:center;vertical-align:middle;width:100px;white-space:nowrap;text-overflow: ellipsis; overflow: hidden;'><a title='" + mmGuige + "'>" + mmGuige + "</a></td>";
                                    mmHtml += "<td style='text-align:center;vertical-align:middle;width:100px;white-space:nowrap;text-overflow: ellipsis; overflow: hidden;'><a title='" + mmXinghao + "'>" + mmXinghao + "</a></td>";
                                    mmHtml += "<td style='text-align:center;vertical-align:middle;'>" + mmZhucezhenghao + "</td>";
                                    mmHtml += "<td style='text-align:center;vertical-align:middle;'>" + mmShengchanshang + "</td>";
                                    mmHtml += "<td style='text-align:center;vertical-align:middle;'>" + mmdanwei + "</td>";
                                    mmHtml += "<td style='text-align:center;vertical-align:middle;'>" + mmjiage + "</td>";
                                    mmHtml += "</tr>";
                                }
                            }

                        }else {
                            _this.show = false;
                        }
                        mmHtml += "</table>";
                        $("#List").html(mmHtml);
                    }else{
                        layer.alert(ppData.message);
                    }
                }

            },"json");
        },

        //跳到首页
        SetPageIndex : function(){
            this.pageIndex = 1;
        },
        SetPageEnd : function(){
            this.pageIndex = this.pageCount;
        },
        //上一页
        SetPageIndexPrePage : function(){
            var PrePage = ((this.pageIndex -1) <= 0) ? 1 : (this.pageIndex -1);
            this.pageIndex = PrePage;
        },
        //下一页
        SetPageIndexNextPage : function(){
            var NextPage = ((this.pageIndex +1) >= this.pageCount) ? this.pageCount : (this.pageIndex +1);
            this.pageIndex = NextPage;
        },
        //跳转界面
        JumpPage : function(){
            if(this.inputPageIndexValue <= 1){
                this.inputPageIndexValue = 1;
            }else if(this.inputPageIndexValue >= this.pageCount){
                this.inputPageIndexValue = this.pageCount;
            }
            this.pageIndex = this.inputPageIndexValue;
            this.inputPageIndexValue = '';
        },

    },
    watch :{
        //监控分页情况，刷新列表
        pageIndex : function(){

            this.bindYiyonghaocaiList();
        }
    }
});
